<?php
namespace Admin\Model;
use Think\Model\RelationModel;
class ProjectModel extends RelationModel {
	public $_validate = array (
		//array('account','/^[a-z]\w{3,}$/i','帐号格式错误',1),
		array('name','require','名称必须',1),
		//array('dh','require','对话必须',1),
		//array('dhcb','require','对话成本必须',1),
		//array('dz','require','到诊必须',1),
		//array('dzcb','require','到诊成本必须',1),
		//array('repassword','password','确认密码不一致',1,'confirm'),*/
		array ('name','','名称已经存在！',1,'unique',3),
		
	);
	protected $_auto = array (
         array('addtime','getAddtime',1,'callback'),
         array('hospitalname','getHospitalname',3,'callback'),
    );
	protected function getAddtime(){ 
		return date("Y-m-d H:i:s",time()); 
	} 
	protected function getHospitalname() {
		$type=I('hospitalid');
		$name=M('Hospital')->field('name')->find($type);
		return $name['name'];
	}
	protected $_link = array (
 		'hospital'=> array(  
     		'mapping_type'=>self::BELONGS_TO,
          	'class_name'=>'hospital',
          	'foreign_key'=>'hospitalid',
          	'mapping_name'=>'hospital',
 		),
 		'users'=> array(  
     		'mapping_type'=>self::MANY_TO_MANY,
			'class_name'=>'user',
			'mapping_name'=>'users',
			'foreign_key'=>'project_id',
			'relation_foreign_key'=>'user_id',
			'relation_table'=>'project_user',
 		),
		
	);
}
?>